package com.arvato.wxwork.service.ncc;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.arvato.minipro.bean.bean_dto.common.PageData;
import com.arvato.minipro.bean.bean_dto.common.Query;
import com.arvato.wxwork.bean.bean_do.ncc.WxworkGreetDo;
import com.arvato.wxwork.bean.bean_vo.ncc.WxworkGreetVo;
import com.arvato.wxwork.bean.bean_vo.ncc.WxworkNccInfoVo;
import com.arvato.wxwork.mapper.ncc.WxworkGreetMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;


@Service
@Transactional
public class WxworkGreetService {
	
	@Autowired
	private WxworkGreetMapper wxworkGreetMapper;
	
	/**
	 * 查询问候语列表 分页查询
	 * @param query
	 * @param integer 
	 * @return
	 */
	public PageData listGreetByQuery(Query query, Integer pageNum, Integer pageSize) {
		// 设置分页参数
		PageHelper.startPage(pageNum, pageSize);
		List<WxworkGreetVo> greetList = wxworkGreetMapper.listGreetByQuery(query);
		PageInfo<WxworkGreetVo> pageInfo = new PageInfo<WxworkGreetVo>(greetList);
		PageData pageData = new PageData(pageInfo.getTotal(), pageInfo.getList());
		return pageData;
	}
	
	/**
	 * 查询问候语列表 不分页查询
	 * @param query
	 * @param integer 
	 * @return
	 */
	public List<WxworkGreetVo> listGreetByQuery(Query query) {
		List<WxworkGreetVo> greetList = wxworkGreetMapper.listGreetByQuery(query);
		return greetList;
	}
	
	/**
	 * 根据ID查询详情
	 * @param areaId
	 * @return
	 */
	public WxworkGreetVo getGreetById(String id) {
		return wxworkGreetMapper.getGreetById(id);
	}
	
	/**
	 * 新增问候语
	 * @param GreetDo
	 */
	public int insert(WxworkGreetDo greetDo) {
		return wxworkGreetMapper.insert(greetDo);
	}
		
	/**
	 * 修改问候语
	 * @param greetDo
	 * @return
	 */
	public int update(WxworkGreetDo greetDo) {
		return wxworkGreetMapper.update(greetDo);
	}
	/**
	 * 删除问候语
	 * @param GreetId
	 * @return
	 */
	public int delete(String id) {
		return wxworkGreetMapper.delete(id);
	}
	
	/**
	 * 检查是否有重复的问候语
	 * 一个品牌一个活动只能有一个默认的问候语
	 * @param brand
	 * @param campaign
	 * @param type
	 * @return
	 */
	public boolean check(String brand, String campaign, Integer type) {
		Query query = new Query();
		query.put("brand", brand);
		query.put("campaign", campaign);
		query.put("type", type);
		List<WxworkGreetVo> list = wxworkGreetMapper.listGreetByQuery(query);
		if(list.size() >= 1) {
			return true;
		}
		return false;
	}

	public List<WxworkGreetDo> getGreetByIdOrStaffId(Query query) {
		return 	wxworkGreetMapper.getGreetByIdOrStaffId(query);
	}

	public PageData customerInfo(Query query, Integer pageNum, Integer pageSize) {
		// 设置分页参数
		PageHelper.startPage(pageNum, pageSize);
		List<WxworkNccInfoVo> greetList = wxworkGreetMapper.customerInfo(query);
		PageInfo<WxworkNccInfoVo> pageInfo = new PageInfo<WxworkNccInfoVo>(greetList);
		PageData pageData = new PageData(pageInfo.getTotal(), pageInfo.getList());
		return pageData;
	}
	
}
